<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改教学物品')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goods-edit" th:object="${sysTeachGoods}">
            <input id="id" name="id" th:field="*{id}" type="hidden">
            <input id="tenantId2" name="tenantId2" th:field="*{tenantId}" type="hidden">
           <!-- <div class="form-group" th:if="${@permission.hasPermi('system:superAdmin:opt')} != 'hidden'">
                <label class="col-sm-3 control-label">请选择租户：</label>
                <div class="col-sm-8">
                    <select name="tenantId" id="tenantId"  class="form-control" disabled>
                        <option th:each="t : ${tenantList}" th:selected="${t.tenantId eq sysSubject.tenantId}"  th:text="${t.tenantName}" th:value="${t.tenantId}"></option>
                    </select>
                </div>
            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required" >教学物品名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required maxlength="30">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">单位：</label>
                <div class="col-sm-8">
                    <select th:field="*{unit}" name="unit" required th:with="type=${@dict.getType('tenant_teach_goods_unit')}" class="form-control">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictValue}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类：</label>
                <div class="col-sm-8">
                    <select th:field="*{type}" name="type" required th:with="type=${@dict.getType('tenant_teach_goods_type')}" class="form-control">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictValue}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">单价：</label>
                <div class="col-sm-8">
                    <input  th:field="*{price}" id="price" name="price" class="form-control" type="text" maxlength="8" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea id="remark" th:field="*{remark}" name="remark" class="form-control" maxlength="300"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        jQuery.validator.addMethod("minNumber",function(value, element){
            var returnVal = true;
            inputZ=value;
            var ArrMen= inputZ.split(".");    //截取字符串
            if(ArrMen.length==2){
                if(ArrMen[1].length>2){    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为两位");

        var prefix = ctx + "teach/goods"
        $("#form-goods-edit").validate({
            onkeyup: false,
            rules:{
                name:{
                    remote: {
                        url: ctx + "teach/goods/checkNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "name" : function() {
                                return $.common.trim($("#name").val());
                            },
                            "id" : function() {
                                return $.common.trim($("#id").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                price: {
                    required: true,    //要求输入不能为空
                    number: true,     //输入必须是数字
                    min: 0.01,          //输入的数字最小值为0.01，不能为0或者负数
                    minNumber: $("#price").val()    //调用自定义验证
                }
            },
            messages: {
                "name": {
                    remote: "名称已存在！"
                },
                "price": {
                    required: "请填写充值金额",
                    number: "请正确输入金额",
                    min: "输入最小金额为0.01",
                    length: "输入数字最多小数点后两位"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-goods-edit').serialize());
            }
        }
    </script>
</body>
</html>